using Microsoft.AspNetCore.Mvc;
using ZR.Model.TaskManage.Dto;
using ZR.Model.TaskManage;
using ZR.Service.TaskManage.ITaskManageService;
using ZR.Admin.WebApi.Filters;

//创建时间：2025-04-20
namespace ZR.Admin.WebApi.Controllers.TaskManage
{
    /// <summary>
    /// AGV任务
    /// </summary>
    [Verify]
    [Route("TaskManage/TaskAgv")]
    public class TaskAgvController : BaseController
    {
        /// <summary>
        /// AGV任务接口
        /// </summary>
        private readonly ITaskAgvService _TaskAgvService;

        public TaskAgvController(ITaskAgvService TaskAgvService)
        {
            _TaskAgvService = TaskAgvService;
        }

        /// <summary>
        /// 查询AGV任务列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("pageList")]
        [ActionPermissionFilter(Permission = "task:agv:list")]
        public IActionResult PageTaskAgv([FromQuery] TaskAgvQueryDto parm)
        {
            var response = _TaskAgvService.GetPageList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询AGV任务详情
        /// </summary>
        /// <param name="TaskNo"></param>
        /// <returns></returns>
        [HttpGet("{TaskNo}")]
        [ActionPermissionFilter(Permission = "task:agv:query")]
        public IActionResult GetTaskAgv(long TaskNo)
        {
            var response = _TaskAgvService.GetInfo(TaskNo);
            
            var info = response.Adapt<TaskAgvDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加AGV任务
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "task:agv:add")]
        [Log(Title = "AGV任务", BusinessType = BusinessType.INSERT)]
        public IActionResult AddTaskAgv([FromBody] TaskAgvDto parm)
        {
            var modal = parm.Adapt<TaskAgv>().ToCreate(HttpContext);

            var response = _TaskAgvService.AddTaskAgv(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新AGV任务
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "task:agv:edit")]
        [Log(Title = "AGV任务", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateTaskAgv([FromBody] TaskAgvDto parm)
        {
            var modal = parm.Adapt<TaskAgv>().ToUpdate(HttpContext);
            var response = _TaskAgvService.UpdateTaskAgv(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除AGV任务
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete")]
        [ActionPermissionFilter(Permission = "task:agv:delete")]
        [Log(Title = "AGV任务", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteTaskAgv([FromBody] long[] ids)
        {
            return ToResponse(_TaskAgvService.Delete(ids));
        }

    }
}